package com.kwok.hotel.es.db.entity.bo;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;

/**
 * ES的实体对象
 */
@Data
//设置索引库名
@Document(indexName = "hotel_index")
//设置分片为1，副本为0
@Setting(shards = 1,replicas = 0)
public class HotelBo {

    @Id
    private Long id;
    //酒店标题
    @MultiField(
            mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
            otherFields = {
                    @InnerField(suffix = "pinyin", type = FieldType.Text, analyzer = "pinyin")
            }
    )
    private String subject;
    //酒店图片
    @Field(type = FieldType.Keyword, index = false)
    private String image;
    //价格
    @Field(type = FieldType.Double)
    private Double price;
    //评分
    @Field(type = FieldType.Float)
    private Float score;
    //标签，用逗号分隔
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String tags;
    //星级
    @Field(type = FieldType.Integer)
    private Integer star;
    //经度
    //private Double lon;
    //纬度
    //private Double lat;

    @GeoPointField
    private GeoPoint hotelLocation;

    //手动设置酒店经纬度
    public void setLocation(double lon, double lat){
        hotelLocation = new GeoPoint(lat, lon);
    }

}
